package com.tanqidi.arcgisandroid.ui.test

import android.os.Bundle
import android.os.Environment
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.esri.arcgisruntime.data.Geodatabase
import com.google.ar.sceneform.rendering.EnvironmentalHdrLightEstimate
import com.tanqidi.arcgisandroid.R
import com.tanqidi.arcgisandroid.databinding.FragmentTestBinding
import java.io.File

class TestFragment : Fragment() {

    private lateinit var binding: FragmentTestBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = FragmentTestBinding.inflate(layoutInflater)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        initTopBar()
        testGeodatabase()
        return binding.root
    }

    private fun initTopBar(){
        binding.topAppBar.setNavigationOnClickListener { findNavController().navigateUp() }
    }

    private fun testGeodatabase(){
        val mygdbPath = Environment.getExternalStorageDirectory().absolutePath + File.separator + getString(R.string.app_name) + File.separator + getString(R.string.gdb) + File.separator + "my.geodatabase"
        val createAsync = Geodatabase.createAsync(mygdbPath)
        createAsync.addDoneListener {
            val geodatabase = createAsync.get()
            val toString = geodatabase.toString()
        }
    }

}